home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
JCSM Shareware Collection 1996 September
/
JCSM Shareware Collection (JCS Distribution) (September 1996).ISO
/
bother__
/
cenvid.zip
/
CENVIDOS.ZIP
/
AUTOLOAD.CMM
< prev
next >
Wrap
Text File
|
1995-02-14
|
5KB
|
168 lines
// AutoLoad.cmm
//**************************************************************************
//****** BEGIN SECTION TO HANDLE INTERNAL COMMANDS FOR THE CLI SHELL *******
//**************************************************************************
// create and sort list of commands for CMD.EXE call
SystemCommands = {
"DIR",
"CLS",
"MKDIR",
"MD",
"RMDIR",
"RD",
"ERASE",
"DEL",
"TYPE",
};
qsort(SystemCommands,"stricmp");
// create and sort list of commands handled internally
InternalCommands = {
"CD",
"SET"
};
qsort(InternalCommands,"stricmp");
// set up filter to handle each command input
ShellFilterCommand("AutoloadFilterCommand");
AutoloadFilterCommand(pCommand)
{
// if command found in SystemCommands list then execute it immediately
// with CMD.EXE then, else check internal cmds and some others
if ( 1 == sscanf(pCommand,"%s",lCommand) ) {
if ( -1 != bsearch(lCommand,SystemCommands,"stricmp") ) {
system(pCommand);
pCommand[0] = '\0';
} else if ( -1 != bsearch(lCommand,InternalCommands,"stricmp") ) {
sprintf(lInternalFunction,"InternalCommand_%s",strupr(lCommand));
lParm = pCommand + strlen(lCommand);
while( isspace(lParm[0]) ) lParm++;
function(lInternalFunction,lParm);
pCommand[0] = '\0';
} else if ( !strcmp(lCommand+1,":") ) {
// change drive
#define ORD_DOS32SETDEFAULTDISK 220
DynamicLink("doscalls",ORD_DOS32SETDEFAULTDISK,BIT32,CDECL,
toupper(lCommand[0])-'A'+1);
pCommand[0] = '\0';
}
}
}
InternalCommand_CD(pParm)
{
// change directory
if ( !pParm[0] ) {
// no other argument, so just display current dir
printf("%s\n",FullPath("."));
} else {
lReg.ah = 0x3B;
lReg.ds = segment(pParm);
lReg.dx = offset(pParm);
interrupt(0x21,lReg);
}
}
//************************************************************************
//****** END SECTION TO HANDLE INTERNAL COMMANDS FOR THE CLI SHELL *******
//************************************************************************
//****************************************************************************
//****** BEGIN SECTION TO HANDLE HISTORY AND EDITING FOR THE CLI SHELL *******
//****************************************************************************
#define EXT_KEY_HOME 0x47
#define EXT_KEY_END 0x4F
#define EXT_KEY_UP 0x48
#define EXT_KEY_DOWN 0x50
#define HISTORY_MAX_MEMORY 20 // maximum values to hold in history
gHistoryList;
gHistoryCount = 0;
gReviewLine = HISTORY_MAX_MEMORY; // when scrolling through buffer, this is line being reviewed
// set up filter to handle every special character input
ShellFilterCharacter("AutoloadFilterCharacter",False);
AutoloadFilterCharacter(pCommand,pPosition,pKey,pIsExtended,pIsAlnum)
{
if ( pIsExtended ) {
switch( pKey ) {
case EXT_KEY_HOME:
pPosition = 0;
break;
case EXT_KEY_END: // END
pPosition = strlen(pCommand);
break;
case EXT_KEY_UP:
if ( gHistoryCount ) {
if ( gHistoryCount <= ++gReviewLine )
gReviewLine = 0;
strcpy(pCommand,gHistoryList[gReviewLine]);
pPosition = strlen(pCommand);
pKey = 0;
return True;
}
break;
case EXT_KEY_DOWN:
if ( gHistoryCount ) {
if ( --gReviewLine < 0 )
gReviewLine = gHistoryCount - 1;
strcpy(pCommand,gHistoryList[gReviewLine]);
pPosition = strlen(pCommand);
pKey = 0;
return True;
}
break;
}
} else if ( '\r' == pKey ) {
AddToHistory(pCommand);
}
return False;
}
AddToHistory(pCommand)
{
// skip all spaces at beginning of command
strcpy(lCommand,pCommand);
lCommand += strspn(lCommand," ");
// remove any spaces at end of command
while ( (lLastSpace = strrchr(lCommand,' ')) && !lLastSpace[1] )
lLastSpace[0] = '\0';
// if no command remains then do not save
if ( !lCommand[0] )
return;
// if this entry is already in the history then remove that entry so this
// one can replace as most recent. Otherwise remove oldest entry if there
// are up to max in the buffer
bool lNewEntry = True;
for ( lOldEntry = 0; lOldEntry < gHistoryCount; lOldEntry++ ) {
if ( !stricmp(lCommand,gHistoryList[lOldEntry]) ) {
lNewEntry = False;
break;
}
}
// move all entries down one to fill in the old gap
while ( lOldEntry-- )
gHistoryList[lOldEntry+1] = gHistoryList[lOldEntry];
// new command goes to top of list
gHistoryList[0] = lCommand;
if ( gHistoryCount < HISTORY_MAX_MEMORY && lNewEntry )
gHistoryCount++;
gReviewLine = gHistoryCount;
}
//**************************************************************************
//****** END SECTION TO HANDLE HISTORY AND EDITING FOR THE CLI SHELL *******
//**************************************************************************